package com.sywb.chuangyebao.contract;

import com.sywb.chuangyebao.Constants;
import com.sywb.chuangyebao.bean.BusinessDetail;
import com.sywb.chuangyebao.utils.HttpCallback;
import com.sywb.chuangyebao.utils.HttpUtils;
import com.sywb.chuangyebao.view.WebActivity;
import com.sywb.chuangyebao.view.dialog.BusinessTVDetailIntroDialog;

import org.bining.footstone.mvp.IView;
import org.bining.footstone.presenter.BasePresenter;
import org.bining.footstone.utils.ToastUtils;

public interface BusinessTVDetailContract {

    interface View extends IView {
        int getDialogViewHeight();

        String getBusinessTVId();

        void startPlay(String videoUrl, String previewPath);

        void initData(String intro, String webContent);
    }

    class Presenter extends BasePresenter<View> {

        private String businessTVId;
        private BusinessDetail businessDetail;

        @Override
        public void onStart() {
            businessTVId = mView.getBusinessTVId();
            getChuangTVDetail();
        }

        public void getChuangTVDetail() {
            HttpUtils.chuangTVDetail(businessTVId, new HttpCallback<BusinessDetail>() {
                @Override
                public void onStart() {
                    super.onStart();
                    onStartAsync();
                }

                @Override
                public void onSuccess(BusinessDetail bDetail) {
                    if (bDetail != null) {
                        businessDetail = bDetail;
                        mView.startPlay(bDetail.media_url, bDetail.media_logo);
                        mView.initData(bDetail.summary, bDetail.url);
                    }
                }

                @Override
                public void onError(String strMsg) {
                    super.onError(strMsg);
                    showMessage(strMsg);
                    if (mView != null) {
                        mView.exit();
                    }
                }

                @Override
                public void onFinish() {
                    super.onFinish();
                    onFinishAsync();
                }
            });
        }

        public void goToIntro() {
            BusinessTVDetailIntroDialog dialogFragment = BusinessTVDetailIntroDialog.newInstance(mView.getDialogViewHeight(), businessDetail.des);
            dialogFragment.show(mView.getMyFragmentManager(), "BusinessTV");
        }

        public void goToChangtantong() {
            mView.advance(WebActivity.class, "畅谈通", businessDetail.changtantong, Constants.COOKIE_CTV);
        }

        public void showDialog() {
            if (businessDetail == null) {
                return;
            }
            ToastUtils.show(mContext, "创TV节目暂不支持分享");
//            new ShareDialog(mActivity, Constants.TOPIC_TYPE_VIDEO, videoInfo.video_id, ShareDialog.TYPE_REPORT, videoInfo.title, videoInfo.desc, videoInfo.logo,
//                    new ShareDialog.LastOneClick() {
//                        @Override
//                        public void onLastOneClick() {
//                        }
//                    }).show();
        }
    }
}

